package view.transitions;

import java.awt.Graphics;
import java.awt.geom.Rectangle2D;
import java.awt.image.BufferedImage;

public class DoorOpen extends Animator {

	private BufferedImage	buffer;
	public DoorOpen(BufferedImage from, BufferedImage to) {
		super(from, new BufferedImage(to.getWidth(), to.getHeight(), BufferedImage.TYPE_INT_ARGB));
		this.buffer = to;
	}

	@Override
	public void animate() {

		this.currentFrame++;

		float midposition = this.overlay.getWidth()/2;
				
		float x2 = this.currentFrame*(midposition / Animator.MAX_FRAMES);
		
		//float x1 = this.currentFrame*(midposition / (Animator.MAX_FRAMES*2));
		
		System.out.println("currentFrame = "+this.currentFrame+", x2= "+x2);

		/* Middle to left -----<<<<<< */

		Graphics g = this.overlay.getGraphics();
		Rectangle2D r2d = new Rectangle2D.Float(x2+midposition-5, this.overlayPosition.y, x2, this.overlay.getHeight());
		g.setClip(r2d);
		g.drawImage(this.buffer, 0, 0, null);
		g.dispose();
		
		/* Middle to right --->>>> */

		Graphics g1 = this.overlay.getGraphics();
		Rectangle2D r2d1 = new Rectangle2D.Float(midposition-x2*2+5 , this.overlayPosition.y, x2, this.overlay.getHeight());
		g1.setClip(r2d1);
		g1.drawImage(this.buffer, 0, 0, null);
		g1.dispose();


	}

}
